<?php

class Confirm_extra_cost extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Confirm_extra_cost':
	 * @var integer $id
	 * @var integer $fk_confirm_id
	 * @var integer $item
	 * @var double $cost
	 * @var integer $state
	 * @var string $create_time
	 */
	
	private $_item=array('0'=>'住宿','1'=>'停车','2'=>'紧急处理','3'=>'其他');
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'confirm_extra_cost';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('cost', 'numerical'),
			array('cost', 'match','pattern' => '/^\d{1,16}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多16位，小数位2位'),
			array('item,cost', 'required'),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'fk_confirm_id' => '外键确认单id',
			'item' => '其他费用项目',
			'cost' => '其他费用金额',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
	
	public function getItemNames(){
		return $this->_item;
	}
	
	public function getItemName($n=null){
		return $this->_item[$n==null?$this->item:$n];
	}
}